<!DOCTYPE html>
<html>

<head>
    <meta name="layout" content="main2"/>
    <g:set var="entityName" value="${message(code: 'user.label', default: 'User')}"/>
    <title>新增附件</title>
    <asset:stylesheet src="homer/vendor/jQuery-File-Upload/css/jquery.fileupload.css"/>
    <asset:stylesheet src="homer/vendor/blueimp-gallery/css/blueimp-gallery.min.css"/>

    <style>

    .img {
        width: 80px;
        height: 58px;
    }

    .fileupload table > tbody > tr > td {
        vertical-align: middle;
    }
    .fileupload-buttonbar button,.files button{
        margin-top: 2px;
    }
    .card-block {
        background-color: #fff;
        border:1px solid #dddddd;
        border-top:none;
    }
    div.tab-content.tabs.card-block {
        border: none;
    }
    </style>
</head>



<body>


  <div class="main-body">
      <div class="page-wrapper">
          <!-- Page-header start -->
          <div class="page-header">
              <div class="page-header-title">
                  <h4>附件管理</h4>
              </div>

              <div class="page-header-breadcrumb">
                  <ul class="breadcrumb-title">
                      <li class="breadcrumb-item">
                          <a href="/salesDashboard/index">
                              <i class="icofont icofont-home"></i>
                          </a>
                      </li>

                      <li class="breadcrumb-item">更换头像</li>
                  </ul>
              </div>
          </div>
          <!-- Page-header end -->
          <!-- Page-body start -->
          <div class="page-body">
              <div class="alert alert-info hide" role="status" id="alert-danger">提醒</div>
              <g:if test="${flash.message}">
                  <div class="message alert alert-info" role="status">${flash.message}
                      <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                          <span aria-hidden="true">×</span></button>
                  </div>
              </g:if>
              <g:hasErrors bean="${this.user}">
                  <ul class="errors" role="alert">
                      <g:eachError bean="${this.user}" var="error">
                          <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
                                  error="${error}"/></li>
                      </g:eachError>
                  </ul>
              </g:hasErrors>
          <!-- Hover table card start -->
                      <ul class="nav nav-tabs  tabs" role="tablist">
                          <li class="nav-item">
                              <a class="nav-link active" data-toggle="tab" href="#tab1" role="tab" aria-expanded="false">更换头像</a>
                             
                          </li>
                          
                      </ul>
                      <div class="cart">
                        <div class="card-block">
                            <!-- Row start -->
                            <div class="row">
                                    <!-- Tab panes -->
                                    <div class="tab-content tabs card-block">
                                        <div class="tab-pane active" id="tab1" role="tabpanel">
                                            <g:form class="fileupload1 form-horizontal" controller="user" action="changeAvatarSave" method="post"
                                                enctype="multipart/form-data">

                                            <div class="form-group row">
                                                <label class="col-md-2 control-label">上传图片</label>

                                                <div class="col-md-8">

                                                    <div class="row fileupload-buttonbar">
                                                        <div class="col-lg-8">
                                                            <span class="btn btn-info fileinput-button">
                                                                <i class="glyphicon glyphicon-plus"></i>
                                                                <span>选择文件</span>
                                                                <input type="file" name="file" id="file1" multiple>
                                                            </span>
                                                            <button type="submit" class="btn btn-primary start">
                                                                <i class="glyphicon glyphicon-upload"></i>
                                                                <span>开始上传</span>
                                                            </button>
                                                            <button type="reset" class="btn btn-warning cancel">
                                                                <i class="glyphicon glyphicon-ban-circle"></i>
                                                                <span>取消上传</span>
                                                            </button>

                                                            <span class="fileupload-process"></span>
                                                        </div>
                                                        <!-- The global progress state -->
                                                        <div class="col-lg-4 fileupload-progress fade">
                                                            <!-- The global progress bar -->
                                                            <div class="progress full progress-striped active" role="progressbar"
                                                                aria-valuemin="0" aria-valuemax="100">
                                                                <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                                                            </div>
                                                            <!-- The extended global progress state -->
                                                            <div class="progress-extended">&nbsp;</div>
                                                        </div>
                                                    </div>
                                                    <!-- The table listing the files available for upload/download -->
                                                    <p style="margin-top: 10px;">
                                                        <code>图片大小不能超过 5M，图片格式为 jpg、png、jpeg</code>
                                                    </p>
                                                    <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>

                                                </div>
                                            </div>
                                        </g:form>
                                        </div>

                                    </div>
                                <!-- </div> -->

                            </div>
                            <!-- Row end -->
                        </div>
                      </div>

                        
          </div>

          <!-- Page-body end -->
      </div>
  </div>

<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even">
    <div class="slides"></div>
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>
</div>

<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload">
        <td>
            <span class="preview"></span>
        </td>
        <td>
            <p class="name">{%=file.name%}</p>
            <strong class="error text-danger"></strong>
        </td>
        <td>
            <p class="size">Processing...</p>
            <div class="progress full progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
        </td>
        <td>
            {% if (!i && !o.options.autoUpload) { %}
                <button class="btn btn-primary start" disabled>
                    <i class="glyphicon glyphicon-upload"></i>
                    <span>上传</span>
                </button>
            {% } %}
            {% if (!i) { %}
                <button class="btn btn-warning cancel">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>取消</span>
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>

<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download">
        <td>
            <span class="preview">
                {% if (file.thumbnailUrl) { %}
                    <a href="{%=file.thumbnailUrl%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img class="img" src="{%=file.thumbnailUrl%}"></a>
                {% } %}
            </span>
        </td>
        <td>
            <p class="name lightBoxGallery">
                {% if (file.url) { %}
                    <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                {% } else { %}
                    <span>{%=file.name%}</span>
                {% } %}
            </p>
            {% if (file.error) { %}
                <div><span class="label label-danger">Error</span>{%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <span class="size">{%=file.size%}</span>
        </td>
        <td>
         {% if (file.error) { %}
          <button class="btn btn-success cancel">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>取消上传</span>
                </button>
          {% } else { %}
               <button class="btn btn-success" type="button">
                    <i class="glyphicon glyphicon-ok"></i>
                    <span>上传成功</span>
               </button>
          {% } %}
        </td>
    </tr>
{% } %}
</script>

<asset:javascript src="homer/vendor/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/tmpl.min.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/load-image.all.min.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/canvas-to-blob.min.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.iframe-transport.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-process.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-image.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-validate.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-ui.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/cors/jquery.xdr-transport.js"/>
<asset:javascript src="homer/vendor/blueimp-gallery/js/jquery.blueimp-gallery.min.js"/>

<script>
    $(function () {

        $('#type option').each(function () {
            var obj = $(this);
            var text = obj.text();
            $(this).attr('text', text);
        });

        $('#file1').change(function ()
        {
            var files = document.getElementById('file1');
            $("#alert-danger").addClass('hide').text("")
            for (var i = 0; i < files.files.length; i++)
            {
                var file = files.files[i];
                if (file.size > 1024*1024*5 + 100) {
                    $("#alert-danger").removeClass('hide').text( file.name+ "头像图片大于5M，请修改后上传")
                    throw new Error("Something went badly wrong!");
                }
            }
        });

        $('.fileupload1').fileupload({
            disableImageResize: /Android(?!.*Chrome)|Opera/
                   .test(window.navigator.userAgent),
            imageMaxWidth: 1200,
            imageMaxHeight: 1200,
            maxFileSize: 5242880,//5M
            maxNumberOfFiles: 1,
            messages: {
                maxNumberOfFiles: '文件个数不能超过1个',
                acceptFileTypes: '文件格式不正确',
                maxFileSize: '文件太大',
                minFileSize: '文件太小'
            },
            acceptFileTypes: /(\.|\/)(jpeg|jpg|png)$/i
        });
    });
</script>
</body>
</html>
